Skip to content

Separate AM/PM picker column (#69) - #86

Merged
troberts-28 merged 4 commits into
developfrom
feature/separate-am-pm-picker
Aug 31, 2026
Merged

Separate AM/PM picker column (#69)#86
troberts-28 merged 4 commits into
developfrom
feature/separate-am-pm-picker

Conversation

@troberts-28

@troberts-28 troberts-28 commented May 10, 2026

Copy link
Copy Markdown
Owner

Closes #69.

Summary

  • New separateAmPmPicker prop on TimerPicker / TimerPickerModal. When combined with use12HourPicker, AM/PM renders as a dedicated scrollable column after seconds and the hour column shows 12, 1, 2, …, 11. Public onDurationChange / latestDuration / setValue keep using 0–23 hours.
  • hourLimit is honoured in separate mode: hour-column rows grey + snap based on the currently-selected AM/PM. The AM/PM column is freely toggleable so users can always switch halves to reach a valid hour. Wraparound limits (max < min) work the same as in the existing 12-hour mode. hourInterval > 1 is respected end-to-end (rendering, snap, greying).
  • Two new style keys for the column: separateAmPmItem and selectedSeparateAmPmItem. pickerColumnWidth.amPm now also works (modal width math routed through the existing resolveColumnWidth helper).
  • Single-mechanism greying + snap. DurationScroll accepts optional getValidValue and isItemDisabled callbacks; TimerPicker injects cross-column context (current AM/PM + hourLimit + hourInterval) through these instead of passing extra prop channels through to PickerItem. No reentrant setValue from the orchestrator.
  • LatestDurationRef = { readonly current: number } replaces the synthetic RefObject<number> cast on latestDuration.hours / latestDuration.*.
  • Internal helper renamed cycleIdxhourSlot (and findNearestValidHourSlot) for readability.
  • README updated with the new prop, the two style keys, and the pickerColumnWidth.amPm option. Example app gains a separateAmPmPicker modal page and a cross-midnight hourLimit test page.

When use12HourPicker is enabled, separateAmPmPicker renders AM/PM as a
dedicated scrollable column after seconds instead of appending it to each
hour. The hours column shows 12, 1, 2, …, 11 in clock order. Public API
(onDurationChange, latestDuration, setValue) keeps using 0–23 hours.

hourLimit is honoured in this mode: the hour column's rows grey based on
the currently selected AM/PM, and momentum-scroll snaps to the nearest
valid hour in that half. The AM/PM column is intentionally limit-free so
users can always toggle halves to reach any valid hour. Wraparound limits
(max < min) are handled the same as in the existing 12-hour mode.

The TimerPickerModal width calculation now counts the AM/PM column when
present, so default styles work without manual pickerColumnWidth tweaks.
maximumHours remains ignored in separate mode (warns at runtime).
…y refs

- DurationScroll gains `getValidValue` + `isItemDisabled` callback props.
  TimerPicker injects cross-column context (current AM/PM, hourLimit,
  hourInterval) through these instead of plumbing combinedHourLimit /
  currentAmPm through DurationScroll → PickerItem.
- One snap path: DurationScroll's onMomentumScrollEnd calls the validate
  callback, no more reentrant setValue from TimerPicker.
- findNearestValidCycleIdx now takes interval and iterates 0..11 step
  interval, so hourInterval > 1 no longer snaps to a non-rendered cycleIdx.
  Adds parameterised interval coverage to the test suite.
- Drop dead selectedAmPmRef + sync useEffect.
- Replace the synthetic `RefObject<number>` cast on latestDuration.hours
  with a proper `LatestDurationRef = { readonly current: number }` type
  used by both TimerPickerRef and TimerPickerModalRef.
- Add "amPm" to PickerColumn so pickerColumnWidth.amPm works and the modal
  width math routes through the existing resolveColumnWidth helper.
cycleIdx was internal jargon. hourSlot reads naturally as 'a slot in the
12-hour clock-face column' where slot 0 is the 12 (noon/midnight) position.
splitHour24 returns { amPm, hourSlot }; findNearestValidHourSlot replaces
findNearestValidCycleIdx; getValidHourSlot/isHourSlotDisabled in TimerPicker.
@JacobCll

JacobCll commented Jul 8, 2026

Copy link
Copy Markdown

This is really useful, please merge!

@troberts-28

Copy link
Copy Markdown
Owner Author

Hey @JacobCll 👋 My bad! left this on ice for too long. Just had a couple of things to check before merging. I'll get it in this weekend

@cjambrosi

Copy link
Copy Markdown

This is very useful. Waiting for the merge!

@troberts-28
troberts-28 merged commit 00f2c3c into develop Aug 31, 2026
@troberts-28

Copy link
Copy Markdown
Owner Author

Just released this in v2.7.0 - apologies for the delay!

@troberts-28
troberts-28 deleted the feature/separate-am-pm-picker branch August 31, 2026 22:09
troberts-28 added a commit to JasperVercammen/react-native-timer-picker that referenced this pull request Sep 1, 2026
Brings the branch up to date with develop, which gained separateAmPmPicker
(troberts-28#69/troberts-28#86) and the snap/greying callback refactor after this branch forked.

Conflicts in DurationScroll.tsx, DurationScroll/types.ts and TimerPicker.tsx
are all cases of develop refactoring underneath the branch rather than genuine
semantic overlap, so they are resolved to develop's side. The accessibility
layer in those three files is reinstated and corrected in the following commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cz8qeb64YfaLZa6MDf2SY5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants